package com.pb.infra.auth.entity.custom;

import com.pb.infra.auth.entity.pbsys.PriviUser;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class PriviUserCustom extends PriviUser implements UserDetails {
    /**
     * 用户号
     */
    private String userId;

    private String roleId;

    /**
     * 用户名
     */
    private String userName;

    /**
     * 机构号
     */
    private String orgId;

    /**
     * 机构名称
     */
    private String orgName;

    /**
     * 岗位编号
     */
    private String postId;

    /**
     * 岗位名称
     */
    private String postName;

    /**
     * 手机号
     */
    private String phone;

    /**
     * 用户角色
     */
    private String[] roleIds;

    private String passFlag;

    private String corpId;

    private List<PriviRoleCustom> roles;

    private String updateUser;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        if (roles != null && roles.size() > 0) {
            List<SimpleGrantedAuthority> authorities = new ArrayList<>(roles.size());
            for (PriviRoleCustom role : roles) {
                authorities.add(new SimpleGrantedAuthority(role.getRoleName()));
            }
            return authorities;
        } else {
            return null;
        }
    }

    @Override
    public String getPassword() {
        return null;
    }

    @Override
    public String getUsername() {
        return userName;
    }

    @Override
    public boolean isAccountNonExpired() {
        return false;
    }

    @Override
    public boolean isAccountNonLocked() {
        return false;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return false;
    }

    @Override
    public boolean isEnabled() {
        return false;
    }
}
